﻿<Window x:Class="WebCam.WebCam3Window"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    KeyDown="Window_KeyDown" 
    xmlns:z="clr-namespace:BrainTechLLC.WebCamLib3;assembly=BrainTechLLC.WebCamLib3"
    xmlns:y="clr-namespace:WebCam"
    xmlns:wpf="clr-namespace:BrainTechLLC.WPF;assembly=BrainTechLLC.WPF"
    Title="WebCam3Window" Width="400" Height="300">
    <Window.Resources>
        <wpf:VisibilityConverter x:Key="VisibilityConverter"/>
        <wpf:OppositeConverter x:Key="OppositeConverter"/>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="20"/>
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>
        <y:SelectCaptureDevice x:Name="selectCaptureDevice" Grid.RowSpan="2"
                               UseDevice="selectCaptureDevice_UseDevice" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Top"/>
        <Menu Grid.RowSpan="2" Visibility="{Binding ElementName=selectCaptureDevice, Path=Visibility, Converter={StaticResource OppositeConverter}}">
            <MenuItem Header="_Options">
                <MenuItem IsCheckable="True" x:Name="btnTopmost" Checked="btnTopmost_Checked" Unchecked="btnTopmost_Unchecked" Header="Window Remains Topmost"/>
                <MenuItem IsCheckable="True" x:Name="btnToggleVideo" Checked="btnStartStopVideo_Checked" Unchecked="btnStartStopVideo_Unchecked" Header="Video Enabled"/>
                <MenuItem IsCheckable="True" Header="Disable Motion" x:Name="btnMotion" IsChecked="{Binding Mode=TwoWay, Path=Enabled}" 
                          Visibility="{Binding ElementName=btnToggleVideo, Mode=OneWay, Path=IsChecked, Converter={StaticResource VisibilityConverter}}"/>
                <MenuItem IsCheckable="True" x:Name="btnMovementAlarm" Header="Movement Alarm"  IsChecked="{Binding Mode=TwoWay, Path=MovementAlarmOn}" Checked="btnMovementAlarm_Checked"
                         Visibility="{Binding ElementName=btnMotion, Mode=OneWay, Path=IsChecked, Converter={StaticResource VisibilityConverter}}"/>
                <MenuItem Header="Clear FPS" x:Name="btnClearFPS" Click="btnClearFPS_Click"
                    Visibility="{Binding ElementName=btnToggleVideo, Mode=OneWay, Path=IsChecked, Converter={StaticResource VisibilityConverter}}"/>
            </MenuItem>
            <MenuItem Header="_Select">
                <MenuItem x:Name="btnSelectCapture" Header="_Select Capture Device" />
                <MenuItem x:Name="mnuHostName" Header="_Host">
                    <TextBox x:Name="txtHostName" Text="{Binding Mode=TwoWay, Path=HostName}"/>
                </MenuItem>
            </MenuItem>
            <MenuItem FontSize="9" Background="White"  x:Name="txtMotion" Header="{Binding Mode=OneWay, Path=LastMotionDetected, StringFormat=g}" MouseLeftButtonDown="txtMotion_MouseLeftButtonDown" Visibility="Collapsed" Foreground="DarkRed">
            </MenuItem>
            <MenuItem FontSize="9" Background="White"  x:Name="txtWarning" Header="" Foreground="DarkBlue" 
                Visibility="{Binding ElementName=btnToggleVideo, Mode=OneWay, Path=IsChecked, Converter={StaticResource VisibilityConverter}}" >
            </MenuItem>
            <MenuItem FontSize="9" Background="White"  x:Name="txtFPS" Header="" Foreground="DarkGreen"
                       Visibility="{Binding ElementName=btnToggleVideo, Mode=OneWay, Path=IsChecked, Converter={StaticResource VisibilityConverter}}">
            </MenuItem>
            <MenuItem Header="_View">
                <MenuItem Header="Motion Settings"  x:Name="btnMotionSettings" Click="btnMotionSettings_Click"
                    Visibility="{Binding ElementName=btnMotion, Mode=OneWay, Path=IsChecked, Converter={StaticResource VisibilityConverter}}"/>
                <MenuItem Header="Video Settings"  x:Name="btnVideoSettings" Click="btnVideoSettings_Click"
                    Visibility="{Binding ElementName=btnToggleVideo, Mode=OneWay, Path=IsChecked, Converter={StaticResource VisibilityConverter}}"/>
            </MenuItem>
        </Menu>
        <z:CameraControl Grid.Row="1" x:Name="webCamControl" Width="Auto" Height="Auto"  Canvas.ZIndex="1"
                                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
    </Grid>
</Window>
